package com.aaa.controller;

import com.aaa.pojo.Student;
import com.aaa.service.StudentService;
import com.aaa.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController  //该类种所有方法的返回都是json格式
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("getById/{sId}") //restful风格 PathVariable请求地址种{}中的内容
    public Result getById(@PathVariable Integer sId){
        return studentService.queryById(sId);
    }
    @GetMapping ("getAll") //restful风格 PathVariable请求地址种{}中的内容
    public Result getAll(){
        return studentService.queryAll();
    }
//    @PutMapping  查询 get提交  删除 delete  修改 PUT提交  添加 post提交
    //关于:CRUD 增删改
    @PostMapping ("insert")
    public void insert(@RequestBody Student student){
        studentService.insert(student);
    }
    @DeleteMapping("deleteById/{sId}")
    public void delete(@PathVariable Integer sId){
        studentService.deleteById(sId);
    }
    @PutMapping("updates")
    public void update(@RequestBody Student student){
        studentService.update(student);
    }
}
